package com.lw.ai.service;

import com.lw.ai.model.Book;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
@Service
public class BookServiceImplByMemory  implements BookService {
    Map<String, Book> map=new HashMap<>();
    {
        Book book=new Book();
        book.setNumber("1001");
        book.setBookName("java从入门到精通");
        book.setPrice(99.9);
        book.setPublish("清华大学出版社");
        map.put(book.getNumber(),book);
        Book book1=new Book();
        book1.setNumber("1002");
        book1.setBookName("Python从入门到精通");
        book1.setPrice(199.9);
        book1.setPublish("清华大学出版社");
        map.put(book1.getNumber(),book1);

    }
    @Override
    public Map<String, Book> findBook() {
        return map;
    }

    @Override
    public Book findBookById(String  id) {
        return map.get(id);
    }

    @Override
    public Book addBook(Book book) {
        return map.put(book.getNumber(), book);
    }

    @Override
    public Book updateBook(Book book) {
        return map.put(book.getNumber(), book);
    }

    @Override
    public Book deleteBook(String  id) {
        Book remove = map.remove(id);
        return remove;
    }
}
